package game.manager
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Point;

	public class SceneManager
	{
		// layers
		
		private var _mapLayer:Sprite = new Sprite();
		
		private var _movesLayer:Sprite = new Sprite();
		
		private var _stationaryLayer:Sprite = new Sprite();
		
		private var _containerLayer:Sprite = null;
		
		// dictionarys
		
		private var _movesItemjKeyToType:Object = {};
		
		private var _movesItemKeyToProperty:Object = {};
		
		private var _stationaryItemKeyToType:Object = {};
		
		private var _stationaryItemKeyToProperty:Object = {};
		
		// event names and handlers
		
		public static const EVENT_REGISTER_MOVIES:String = "1";
		public static const EVENT_REGISTER_STATIONARY:String = "2";
		public static const EVENT_UPDATE_MOVIES:String = "3";
		public static const EVENT_UPDATE_STATIONARY:String = "4";

		private var _eventNameToEventHandler:Object = {};

		
		public static function init(container:Sprite):void {
			_instance._containerLayer = container;
		}
		
		public static function switchMap(newly:String, x:Number, y:Number):void
		{
			
		}
		
		/**
		 * 
		 * @param itemKey
		 * @param itemType
		 * 
		 */		
		public static function registerMovesItem(itemKey:String, itemType:String):void
		{
			_instance._movesItemjKeyToType[itemKey] = itemType;
			_instance._stationaryItemKeyToProperty[itemKey] = {};
			
			if (_instance._eventNameToEventHandler[EVENT_UPDATE_MOVIES] != null)
				_instance._eventNameToEventHandler[EVENT_UPDATE_MOVIES](itemKey, itemType);
		}
		
//		public static function registerStationaryItem(itemKey:String, itemType:String):void
//		{
//			_instance._stationaryItemKeyToType[itemKey] = itemType;
//			_instance._stationaryItemKeyToProperty[itemKey] = {};
//			
//			if (_instance._onRegisterStationaryItemHandler != null)
//				_instance._onRegisterStationaryItemHandler();
//		}
		
		/**
		 * 
		 * @param itemKey
		 * @param propertyName
		 * @param propertyValue
		 * 
		 */		
		public static function setMovesItemProperty(itemKey:String, propertyName:String, propertyValue:*):void
		{
			if (!_instance._movesItemKeyToProperty.hasOwnProperty(itemKey))
				_instance._movesItemKeyToProperty[itemKey] = {};
			
			_instance._movesItemKeyToProperty[itemKey][propertyName] = propertyValue;
			
			if (_instance._eventNameToEventHandler[EVENT_UPDATE_STATIONARY] != null)
				_instance._eventNameToEventHandler[EVENT_UPDATE_STATIONARY](itemKey, propertyName, propertyValue);
		}
		
		/**
		 * 
		 * @param itemKey
		 * @param propertyName
		 * @return 
		 * 
		 */		
		public static function getMovesItemProperty(itemKey:String, propertyName:String):*
		{
			return _instance._stationaryItemKeyToProperty[itemKey] ? 
				_instance._stationaryItemKeyToProperty[itemKey][propertyName]:null;
		}
		
		/**
		 * 
		 * @param eventName
		 * @param handler
		 * 
		 */		
		public static function setEventHandler(eventName:String, handler:Function):void
		{
			_instance._eventNameToEventHandler[eventName] = handler;
		}
		
		
		private static var _instance:SceneManager = new SceneManager();
		public function SceneManager()
		{
			
		}
	}
}